/*
 * @Description: 
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2020-12-08 16:06:46
 * @LastEditors: Seven
 * @LastEditTime: 2021-01-21 09:49:54
 */
/**
 * 封装Axios
 * 处理请求、响应错误信息
 */
import axios from 'axios' //引用axios
const baseURL = 'http://39.99.200.83:12306';

// create an axios instance
const service = axios.create({
  baseURL, 
  timeout: 5000 // request timeout
})

// 请求拦截
service.interceptors.request.use( config => {
    let token = $nuxt.$store.state.token
    if (token) {
        //将token放到请求头发送给服务器,将tokenkey放在请求头中
        config.headers.token = token;     
    }
    // 1pc 2小程序
    config.headers.source = 1
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// 响应拦截
service.interceptors.response.use(function (response) {

  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});

export default service //导出封装后的axios